package com.example.dziennikposilkow;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.example.dziennikposilkow.importXML.XMLReader;
import com.example.dziennikposilkow.model.Products;

public class DziennikMainActivity extends Activity {
	//public  XMLReader xmlReader = new XMLReader();
    
	public Products[] products;
	ImageButton ibDane;
	ImageButton ibKalendarz;
	ImageButton ibPosilki;
	ImageButton ibKompozytor;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_dziennik_main);
        //setContentView(R.layout.splash_main);
        
        if (Singleton.getInstance() == null)
        {
        	initSingleton();
        
        //new XMLReader().readData(getResources().getXml(R.xml.moje), "Moje");
        
       // products = new XMLReader().readAllData(getResources().getXml(R.xml.produkty));
        
	        XMLReader xmlReader = new XMLReader();
	        products = new Products[xmlReader.subcategories.length];
	        for (int i = 0; i < xmlReader.subcategories.length; i++){
	        	products[i] = new XMLReader().readData(getResources().getXml(R.xml.produkty), xmlReader.subcategories[i]);
	        }
	 
	        Singleton.getInstance().products = products;
	        
	    }       
        
        
		ibDane = (ImageButton) findViewById(R.id.Dane);
		ibDane.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), Dane.class);
				startActivity(intent);
			    
				
			}
		});
		
		ibKalendarz = (ImageButton) findViewById(R.id.Kalendarz);
		ibKalendarz.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), Kalendarz.class);
				startActivity(intent);
			    
				
			}
		});
		
		ibPosilki = (ImageButton) findViewById(R.id.Posilki);
		ibPosilki.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), Produkty.class);
				startActivity(intent);
			    
				
			}
		});
		
		ibKompozytor = (ImageButton) findViewById(R.id.Kompozytor);
		ibKompozytor.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), KompozytorPosilkow.class);
				startActivity(intent);
			    
				
			}
		});
		
        //Intent intent = new Intent(getApplicationContext(), StartPage.class);
        //startActivity(intent);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        /*getMenuInflater().inflate(R.menu.activity_dziennik_main, menu);
        menu.findItem(R.id.menu_dane).setIntent(new Intent(this, Dane.class));
        menu.findItem(R.id.menu_kalendarz).setIntent(new Intent(this, Kalendarz.class));
        menu.findItem(R.id.menu_kompozytor).setIntent(new Intent(this, KompozytorPosilkow.class));
        menu.findItem(R.id.menu_produkty).setIntent(new Intent(this, Produkty.class));*/
        
        super.onCreateOptionsMenu(menu);
        return true;
    }
    
	protected void initSingleton()
	{
		// Initialize the instance of Singleton
		Singleton.initInstance();
	}


    
}